import api from '@/api'
import down from '@/api/down'
import axios from 'axios'


export let getFileList = path => {
  let data = {
    'path': path
  }
  return api.post('/file/list', data)
}

export let mkDir = (path, dirName) => {
  let data = {
    'path': path,
    'dirName': dirName

  }
  return api.post('/file/mkDir', data)
}
export let del = (path, isRecycle) => {
  let data = {
    'path': path,
    'isRecycle': isRecycle
  }
  return api.post('/file/delete', data)
}

export let rename = (path, name, newName) => {
  let data = {
    'path': path,
    'name': name,
    'newName': newName
  }
  return api.post('/file/rename', data)
}

export let getDirList = path => {
  let data = {
    'path': path
  }
  return api.post('/file/dir/list', data)
}

export let copy = (path, target) => {
  let data = {
    'path': path,
    'target': target
  }
  return api.post('/file/copy', data)
}

export let move = (path, target) => {
  let data = {
    'path': path,
    'target': target
  }
  return api.post('/file/move', data)
}
export let movePrivate = (path) => {
  let data = {
    'path': path,
  }
  return api.post('/file/move/private', data)
}
export let setDirPermission = (path) => {
  let data = {
    'path': path,
  }
  return api.post('/file/set/dir/permission', data)
}
export let search = name => {
  let data = {
    'name': name,
  }
  return api.post('/file/search', data)
}
// export let download = path => {
//   let data = {
//     'path': path,
//   }
//   return api.post('/file/download', data)
// }
export let download = path => {
  path = window.btoa(window.encodeURIComponent(path))
  return down.get(`/file/download/${path}`)
}
export let ShareDownload = (key, pwd) => {
  return down.get(`/file/share/download/${key}/` + pwd)
}
export let format = format => {
  let data = {
    'format': format,
  }
  return api.post('/file/format', data)

}
